import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn import tree
import graphviz
import pandas as pd

x = pd.read_csv("D:\分类实验2次\\new_titanic.csv", usecols=['Pclass','Sex','Age','SibSp','Parch','Fare','Embarked'])
y = pd.read_csv("D:\分类实验2次\\new_titanic.csv", usecols=['Survived'])
x =np.array(x)
y =np.array(y).ravel()
# print(x)
# print(y)
clf = tree.DecisionTreeClassifier()
clf = clf.fit(x, y)
dot_data = tree.export_graphviz(clf, out_file=None,filled=True, rounded=True,
                      special_characters=True)
graph = graphviz.Source(dot_data)  #graphviz可视化树
graph.render("titanic_DecisionTreeClassifier")
